package com.me.bbs.controller;

import com.me.bbs.anno.RequireLogin;
import com.me.bbs.common.Resp;
import com.me.bbs.service.ICommentLikeService;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author lm
 * @since 2023-01-09
 */
@RestController
@RequestMapping("/commentLike")
public class CommentLikeController {
    @Resource
    ICommentLikeService commentLikeService;
    @PostMapping("/{commentId}")
    @RequireLogin
    public Resp<?> like(@PathVariable String commentId, HttpSession session) throws Exception {
        Long userId = (Long) session.getAttribute("user");
        commentLikeService.like(commentId,userId);
        return Resp.success();
    }

    @DeleteMapping("/{commentId}")
    @RequireLogin
    public Resp<?> cancelLike(@PathVariable String commentId, HttpSession session) throws Exception {
        Long userId = (Long) session.getAttribute("user");
        commentLikeService.cancelLike(commentId,userId);
        return Resp.success();
    }
}
